package models

import (
	"time"

	"github.com/astaxie/beego"
	"github.com/astaxie/beego/orm"
)

type Erc20coin struct {
	Id      int
	Symbol  string
	Price   float64
	Rise    float64
	Created int
}

func init() {
	orm.RegisterModel(new(Erc20coin))
}

func InsertErc20coin(Symbol string, Price, Rise float64) {
	if Price > 0 {
		o := orm.NewOrm()
		erc20 := new(Erc20coin)
		erc20.Price = Price
		erc20.Rise = Rise
		erc20.Symbol = Symbol
		erc20.Created = int(time.Now().Unix())

		o.Insert(erc20)
	} else {
		beego.Debug(Symbol+"InsertErc20coin", "查看")
	}
}

func GetErc20coin(Symbol string) Erc20coin {
	o := orm.NewOrm()
	var erc20coin Erc20coin
	count, _ := o.QueryTable("Erc20coin").Count()

	o.QueryTable("Erc20coin").Filter("Id__gt", count-500).Filter("Symbol", Symbol).OrderBy("-Created").One(&erc20coin)
	return erc20coin
}
